package fetcher

import (
	"net/http"
	"fmt"
	"golang.org/x/text/transform"
	"golang.org/x/text/encoding/simplifiedchinese"
	"io/ioutil"
	"time"
)

var d = time.Tick(1000 * time.Millisecond)

func Fetch(url string) ([]byte, error) {

	resp, err := http.Get(url)
	if (err != nil) {
		fmt.Printf("get url %s error \n", url)
		//todo return err
		panic(err)
	}
	if resp.StatusCode != http.StatusOK {
		//fmt.Printf("statusCode is not correct:%d \n", resp.StatusCode)
		//todo return err
		//panic("")
		return []byte(""), err
	}
	defer resp.Body.Close()
	utf8Reader := transform.NewReader(resp.Body, simplifiedchinese.GBK.NewDecoder())
	return ioutil.ReadAll(utf8Reader)
}
